<template>
    <div class="work-page">
        <div class="page-line">
            <RadioButtonGroupM v-model="tabActive" :list="tabList" />
            <!-- <AdminSearchGroupM @search="onSearch" /> -->
        </div>

        <div class="work-list" v-if="list.length">
            <div class="work-item" v-for="item in list" v-key="item.id">
                <div class="work-item__image">
                    <img :src="item.file +
                        '?x-oss-process=image/watermark,image_' +
                        toBase64(
                            'water/logo_white.png?x-oss-process=image/resize,P_30'
                        ) +
                        ',g_center,t_60'
                        " />
                </div>

                <div class="work-item__info">
                    <div class="work-item__title">{{ item.name }}</div>
                    <div class="work-item__middle">
                        <div class="work-item__middle-group">
                            <img :src="`${_oss_}images/admin/works/time.png`" />
                            {{ item.createtime }}
                        </div>
                        <div class="work-item__middle-group">
                            <img :src="`${_oss_}images/admin/works/view.png`" />
                            {{ item.page_view }}
                        </div>
                    </div>
                    <div class="work-item__footer">
                        <!-- <div class="btn" @click="onEditContent(item, tabActive)">修改</div> -->
                        <div class="btn" @click="onShare(item)">分享</div>
                        <div class="btn" @click="onJumpUrl(item)">预览</div>
                        <div class="btn" @click="onEdit(item)">更新</div>
                        <div class="btn" @click="onDel(item)">删除</div>
                    </div>
                </div>
            </div>
        </div>
        <el-empty :image-size="150" v-else />
    </div>

    <DialogEditWorkM ref="dialogEditWorkRef" @success="onSuccess" />
</template>
<script setup>
import { useContent } from ".";

const dialogEditWorkRef = ref(null);
const {
    list,
    tabActive,
    tabList,
    onJumpUrl,
    onShare,
    onEdit,
    onDelWork,
    onSearch,
    GetList,
} = useContent();

const onSuccess = () => {
    GetList(false);
};

const onEditContent = (item, type) => {
    dialogEditWorkRef.value.show(item, type);
}

const onDel = (item) => {
    Dialog({
        title: "提示",
        message: "是否确认删除？",
    }).then((type) => {
        if (type === "confirm") {
            onDelWork(item);
        }
    });
};

onMounted(() => {
    GetList();
});
</script>
<style lang="scss" scoped>
.page-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    margin-bottom: 15px;
}

.cell-title {
    position: relative;
    color: #5085fb;
    font-size: 14px;
    padding-left: 8px;
    font-weight: 500;

    &::before {
        content: "";
        position: absolute;
        top: 50%;
        left: 0;
        width: 3px;
        height: 13px;
        border-radius: 20px;
        background-color: #5085fb;
        transform: translateY(-50%);
    }
}

.work-list {
    padding: 0 15px 15px;

    .work-item {
        border-radius: 3px;
        width: 100%;
        height: 90px;
        background-color: #fff;
        margin-bottom: 15px;
        padding: 5px;
        display: flex;

        &:last-of-type {
            margin-bottom: 0;
        }

        &__title {
            width: 210px;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }

        &__image {
            width: 100px;
            height: 80px;
            border-radius: 3px;
            overflow: hidden;

            img {
                width: 100%;
                height: 100%;
                object-fit: cover;
            }
        }

        &__info {
            padding-top: 10px;
            padding-left: 10px;
        }

        &__title {
            font-size: 14px;
            color: #333;
        }

        &__middle {
            display: flex;
            align-items: center;
            font-size: 12px;
            margin-top: 10px;
            color: #999;

            &-group {
                display: flex;
                align-items: center;
                margin-right: 10px;
            }

            img {
                width: 14px;
                margin-right: 5px;
            }
        }

        &__footer {
            display: flex;
            align-items: center;
            margin-top: 12px;

            .btn {
                margin-right: 14px;
                line-height: 1em;
                font-size: 13px;
                color: #5085fb;
            }
        }
    }
}
</style>
